﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using LeslieXin.SimpleMMF;

namespace Demo_SimpleMMF
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        SimpleMMF _mmf;

        private void button1_Click(object sender, EventArgs e)
        {
            //启动SimpleMMF
            _mmf = new SimpleMMF(textBox3.Text/*服务名称*/, 
                radioButton1.Checked ? SimpleMMF.MMFRole.Server : SimpleMMF.MMFRole.Client/*作为哪方使用*/);
            if (radioButton1.Checked)
            {
                _mmf.ServerMsgReceived += (sender1,msg) => richTextBox2.Text = msg;
            }
            else
            {
                _mmf.ClientMsgReceived += (sender1, msg) => richTextBox2.Text = msg;
            }

            textBox3.Enabled =
                button1.Enabled =
                radioButton1.Enabled =
                radioButton2.Enabled = false;
            label1.Text = "已启动";
            label1.ForeColor = Color.Green;
        }

        private void richTextBox1_TextChanged(object sender, EventArgs e)
        {
            //发送消息
            _mmf.MMFWrite(richTextBox1.Text);
        }
    }
}
